package com.crazyimp.utilities;

import java.util.ArrayList;

import lt.startup.duobes.Constants;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class Parsers {



	public static ArrayList<Pothole> parsePotholes(String data) {
		ArrayList<Pothole> potholesList = new ArrayList<Pothole>();
		JSONArray jsonArray;
		try {
			jsonArray = new JSONArray(data);
			for (int i = 0; i < jsonArray.length(); i++) {
				Pothole pot = parsePothole(jsonArray.getString(i));
				potholesList.add(pot);
//				Log.e(Constants.LOG, "Adding pot"+pot.toString());
			}
			return potholesList;
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static Pothole parsePothole(String data) {
		try {
			JSONObject json = new JSONObject(data);
			return new Pothole(1, json.getDouble("lon"), json.getDouble("lat"));
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
	}

}
